import type { IPage, IPageQuery } from '@/api/interface/index'

export namespace IProduct {
  // 查询条件
  export interface Query extends IPageQuery {
    tenantId?: string
    deptId?: number
    categoryId?: number
    warehouseId?: number
    name?: string
    image?: string
    productNumber?: string
    enable?: string | boolean
    tagIds?: number[]
    createTimeStart?: string
    createTimeEnd?: string
    updateTimeStart?: string
    updateTimeEnd?: string
  }

  // 编辑form表单
  export interface Form {
    id?: number
    tenantId?: string
    deptId?: number
    categoryId?: number
    warehouseId?: number
    name?: string
    image?: string
    productNumber?: string
    enable?: boolean
    tagIds?: number[]
    productSkus?: ProductSkuInsideDTO[]
  }

  // list或detail返回结构
  export interface Row {
    id?: number
    tenantId?: string
    deptId?: number
    categoryId?: number
    warehouseId?: number
    categoryName?: string
    warehouseName?: string
    name?: string
    image?: string
    productNumber?: string
    enable?: boolean
    createTime?: string
    updateTime?: string
    tags?: TagInfo[]
    productSkus?: ProductSkuRow[]
    productLots?: ProductLotRow[]
  }

  // 标签信息
  export interface TagInfo {
    id: number
    name: string
    backgroundColor?: string
    textColor?: string
    plain?: string
  }

  // 产品规格信息
  export interface ProductSkuRow {
    id?: number
    productId?: number
    name?: string
    image?: string
    stock?: number
    price?: number
    enable?: boolean
    createTime?: string
    updateTime?: string
    productLots?: ProductLotRow[]
  }

  // 产品批次信息
  export interface ProductLotRow {
    id?: number
    skuId?: number
    lotNumber?: string
    title?: string
    stock?: number
    price?: number
    quantity?: number
    storageDate?: string
    productDate?: string
    discardDate?: string
    overhaulLastDate?: string
    overhaulGap?: number
    expirationTime?: string
    overhaulNextDate?: string
  }

  // 物资选择器返回结构
  export interface ProductSelectVO {
    id?: number
    name?: string
    image?: string
    productNumber?: string
    enable?: boolean
    productSkus?: ProductSkuSelectVO[]
  }

  // 物资规格选择器返回结构
  export interface ProductSkuSelectVO {
    id?: number
    productId?: number
    name?: string
    image?: string
    stock?: number
    price?: number
    enable?: boolean
  }

  // 物资创建DTO
  export interface ProductCreateDTO {
    id?: number // 更新时需要
    categoryId?: number
    warehouseId?: number
    name: string
    image?: string
    productNumber?: string
    enable?: boolean
    tagIds?: number[]
    productSkus: ProductSkuInsideDTO[]
  }

  // 物资规格DTO
  export interface ProductSkuInsideDTO {
    id?: number // 规格ID，更新时需要
    name?: string // 规格名称
    image?: string // 规格图片
    stock?: number
    price?: number
    enable?: boolean
    productLots?: ProductLotInsideDTO[]
  }

  // 物资批次DTO
  export interface ProductLotInsideDTO {
    id?: number // 批次ID，更新时需要
    skuId?: number
    lotNumber?: string
    title?: string
    stock?: number
    price?: number
    quantity?: number
    storageDate?: string | undefined
    productDate?: string | undefined
    discardDate?: string | undefined
    overhaulLastDate?: string | undefined
    overhaulGap?: number
    expirationTime?: string | undefined // 过期时间
    overhaulNextDate?: string | undefined // 下次检修时间
  }

  // 物资查询DTO (用于选择器等)
  export interface ProductListDTO extends IPageQuery {
    /** 仓库id */
    warehouseId?: number
    /** 名称 */
    name?: string
    /** 物资编号 */
    productNumber?: string
    /** 标签ID */
    tagIds?: number[]
    /** 分类ID */
    categoryId?: number
    /** 启用状态 */
    enable?: string | boolean
  }

  // 产品选择结果
  export interface ProductSelectResult extends IPage<ProductSelectVO> {}

  // 产品详情
  export interface ProductDetail extends Row {
    /** 描述 */
    description?: string
  }

  // 产品规格详情
  export interface ProductSkuDetail extends ProductSkuRow {
    /** 产品信息 */
    product?: {
      id: number
      name: string
      image?: string
      productNumber: string
    }
  }

  // 购物车项
  export interface CartItem {
    /** 规格ID */
    skuId: number
    /** 规格名称 */
    skuName: string
    /** 产品ID */
    productId: number
    /** 产品名称 */
    productName: string
    /** 产品编号 */
    productNumber: string
    /** 规格图片 */
    image?: string
    /** 单价 */
    price: number
    /** 数量 */
    quantity: number
    /** 库存 */
    stock: number
    /** 总价 */
    totalPrice: number
  }
}
